﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://www.codeplex.com/EmlenMud
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BrainTechLLC;

namespace UserInterface
{
	public partial class AbilitiesEditor : UserControl
	{
		public int _lastRow = -1;

		protected AssociatedIDCollection _abilityList;
		protected AssociatedIDCollection AbilityList
		{
			get { return _abilityList; }
			set { _abilityList = value; UpdateBindings(); }
		}

		public void SetAbilityList(AssociatedIDCollection abilityList)
		{
			AbilityList = abilityList;
		}

		public void UpdateBindings()
		{
			if (_abilityList != null)
			{
				abilityBindingSource.DataSource = _abilityList.ReadItems<BrainTechLLC.Ability>();
			}
		}

		public AbilitiesEditor()
		{
			InitializeComponent();
		}

		private void abilityDataGridView_SelectionChanged(object sender, EventArgs e)
		{
			if (abilityDataGridView.SelectedCells != null && abilityDataGridView.SelectedCells.Count > 0)
			{
				DataGridViewCell cell = abilityDataGridView.SelectedCells[0];

				if (cell.RowIndex == _lastRow)
					return;

				_lastRow = cell.RowIndex;
				Ability s = abilityDataGridView.Rows[cell.RowIndex].DataBoundItem as Ability;
				if (s != null)
				{
					abilityDetails.DataSource = s;
					propertyCollectionEditor1.PropList = s.ThingProperties.Props.AllItems;
				}
			}
		}
	}
}
